/*     */ package com.umeng.newxp.view.widget;
/*     */ 
/*     */ import android.content.Context;
/*     */ import android.graphics.Rect;
/*     */ import android.util.AttributeSet;
/*     */ import android.view.Display;
/*     */ import android.view.MotionEvent;
/*     */ import android.view.View;
/*     */ import android.view.View.OnTouchListener;
/*     */ import android.view.ViewGroup.LayoutParams;
/*     */ import android.view.ViewGroup.MarginLayoutParams;
/*     */ import android.view.WindowManager;
/*     */ import android.widget.FrameLayout.LayoutParams;
/*     */ import android.widget.HorizontalScrollView;
/*     */ import android.widget.LinearLayout;
/*     */ import com.umeng.common.Log;
/*     */ 
/*     */ public class SwipeView extends HorizontalScrollView
/*     */ {
/*  18 */   private static int b = 60;
/*     */   private LinearLayout c;
/*     */   private Context d;
/*     */   private int e;
/*     */   private int f;
/*     */   private int g;
/*  25 */   private boolean h = false;
/*  26 */   private boolean i = false;
/*  27 */   private boolean j = false;
/*  28 */   protected boolean a = false;
/*  29 */   private int k = 0;
/*  30 */   private int l = 0;
/*  31 */   private a m = null;
/*     */   private b n;
/*     */   private View.OnTouchListener o;
/*  34 */   private SwipeViewPointer p = null;
/*     */ 
/*     */   public SwipeView(Context paramContext)
/*     */   {
/*  40 */     super(paramContext);
/*  41 */     this.d = paramContext;
/*  42 */     b();
/*     */   }
/*     */ 
/*     */   public SwipeView(Context paramContext, AttributeSet paramAttributeSet)
/*     */   {
/*  49 */     super(paramContext, paramAttributeSet);
/*  50 */     this.d = paramContext;
/*  51 */     b();
/*     */   }
/*     */ 
/*     */   public SwipeView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
/*     */   {
/*  58 */     super(paramContext, paramAttributeSet, paramInt);
/*  59 */     this.d = paramContext;
/*  60 */     b();
/*     */   }
/*     */ 
/*     */   private void b() {
/*  64 */     Log.a("uk.co.jasonfry.android.tools.ui.SwipeView", "Initialising SwipeView");
/*  65 */     this.c = new LinearLayout(this.d);
/*  66 */     this.c.setOrientation(0);
/*  67 */     super.addView(this.c, -1, new FrameLayout.LayoutParams(-1, 
/*  68 */       -1));
/*     */ 
/*  70 */     setSmoothScrollingEnabled(true);
/*  71 */     setHorizontalFadingEdgeEnabled(false);
/*  72 */     setHorizontalScrollBarEnabled(false);
/*     */ 
/*  74 */     Display localDisplay = ((WindowManager)this.d.getSystemService("window"))
/*  75 */       .getDefaultDisplay();
/*  76 */     this.e = localDisplay.getWidth();
/*  77 */     this.l = this.e;
/*  78 */     this.k = 0;
/*     */ 
/*  80 */     this.n = new b(null);
/*  81 */     super.setOnTouchListener(this.n);
/*     */   }
/*     */ 
/*     */   public boolean onTrackballEvent(MotionEvent paramMotionEvent)
/*     */   {
/*  89 */     return true;
/*     */   }
/*     */ 
/*     */   protected boolean onRequestFocusInDescendants(int paramInt, Rect paramRect)
/*     */   {
/*  95 */     return false;
/*     */   }
/*     */ 
/*     */   public void requestChildFocus(View paramView1, View paramView2)
/*     */   {
/* 101 */     requestFocus();
/*     */   }
/*     */ 
/*     */   public void addView(View paramView)
/*     */   {
/* 109 */     addView(paramView, -1);
/*     */   }
/*     */ 
/*     */   public void addView(View paramView, int paramInt)
/*     */   {
/*     */     Object localObject;
/* 118 */     if (paramView.getLayoutParams() == null) {
/* 119 */       localObject = new FrameLayout.LayoutParams(this.l, -1);
/*     */     } else {
/* 121 */       localObject = paramView.getLayoutParams();
/* 122 */       ((ViewGroup.LayoutParams)localObject).width = this.l;
/*     */     }
/* 124 */     addView(paramView, paramInt, (ViewGroup.LayoutParams)localObject);
/*     */   }
/*     */ 
/*     */   public void addView(View paramView, ViewGroup.LayoutParams paramLayoutParams)
/*     */   {
/* 132 */     paramLayoutParams.width = this.l;
/* 133 */     addView(paramView, -1, paramLayoutParams);
/*     */   }
/*     */ 
/*     */   public void addView(View paramView, int paramInt, ViewGroup.LayoutParams paramLayoutParams)
/*     */   {
/* 141 */     requestLayout();
/* 142 */     invalidate();
/* 143 */     this.c.addView(paramView, paramInt, paramLayoutParams);
/*     */   }
/*     */ 
/*     */   protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
/*     */   {
/* 151 */     super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4);
/* 152 */     if (this.a) {
/* 153 */       scrollToPage(this.k);
/* 154 */       this.a = false;
/*     */     }
/*     */   }
/*     */ 
/*     */   public void setOnTouchListener(View.OnTouchListener paramOnTouchListener)
/*     */   {
/* 163 */     this.o = paramOnTouchListener;
/*     */   }
/*     */ 
/*     */   public LinearLayout getChildContainer()
/*     */   {
/* 176 */     return this.c;
/*     */   }
/*     */ 
/*     */   public int getSwipeThreshold()
/*     */   {
/* 186 */     return b;
/*     */   }
/*     */ 
/*     */   public void setSwipeThreshold(int paramInt)
/*     */   {
/* 197 */     b = paramInt;
/*     */   }
/*     */ 
/*     */   public int getCurrentPage()
/*     */   {
/* 206 */     return this.k;
/*     */   }
/*     */ 
/*     */   public int getPageCount()
/*     */   {
/* 215 */     return this.c.getChildCount();
/*     */   }
/*     */ 
/*     */   public void scrollToPage(int paramInt)
/*     */   {
/* 225 */     a(paramInt, false);
/*     */   }
/*     */ 
/*     */   public void smoothScrollToPage(int paramInt)
/*     */   {
/* 235 */     a(paramInt, true);
/*     */   }
/*     */ 
/*     */   private void a(int paramInt, boolean paramBoolean) {
/* 239 */     int i1 = this.k;
/* 240 */     if ((paramInt >= getPageCount()) && (getPageCount() > 0))
/* 241 */       paramInt--;
/* 242 */     else if (paramInt < 0) {
/* 243 */       paramInt = 0;
/*     */     }
/*     */ 
/* 246 */     if (paramBoolean)
/* 247 */       smoothScrollTo(paramInt * this.l, 0);
/*     */     else {
/* 249 */       scrollTo(paramInt * this.l, 0);
/*     */     }
/* 251 */     this.k = paramInt;
/*     */ 
/* 253 */     if ((this.m != null) && (i1 != paramInt)) {
/* 254 */       this.m.a(i1, paramInt);
/*     */     }
/* 256 */     if ((this.p != null) && (i1 != paramInt)) {
/* 257 */       this.p.setCurrentPage(paramInt);
/*     */     }
/*     */ 
/* 260 */     this.a = (!this.a);
/*     */   }
/*     */ 
/*     */   public int setPageWidth(int paramInt)
/*     */   {
/* 274 */     this.l = paramInt;
/* 275 */     return (this.e - this.l) / 2;
/*     */   }
/*     */ 
/*     */   public int calculatePageSize(ViewGroup.MarginLayoutParams paramMarginLayoutParams)
/*     */   {
/* 291 */     return setPageWidth(paramMarginLayoutParams.leftMargin + paramMarginLayoutParams.width + 
/* 292 */       paramMarginLayoutParams.rightMargin);
/*     */   }
/*     */ 
/*     */   public int getPageWidth()
/*     */   {
/* 301 */     return this.l;
/*     */   }
/*     */ 
/*     */   public void setPageControl(SwipeViewPointer paramSwipeViewPointer)
/*     */   {
/* 312 */     this.p = paramSwipeViewPointer;
/*     */ 
/* 314 */     paramSwipeViewPointer.setPageCount(getPageCount());
/* 315 */     paramSwipeViewPointer.setCurrentPage(this.k);
/* 316 */     paramSwipeViewPointer.setOnPageControlClickListener(new b(this));
/*     */   }
/*     */ 
/*     */   public void addPageControlPointer(int paramInt)
/*     */   {
/* 332 */     if (this.p != null)
/* 333 */       this.p.addPageCount(paramInt);
/*     */   }
/*     */ 
/*     */   public SwipeViewPointer getPageControl()
/*     */   {
/* 343 */     return this.p;
/*     */   }
/*     */ 
/*     */   public void setOnPageChangedListener(a parama)
/*     */   {
/* 371 */     this.m = parama;
/*     */   }
/*     */ 
/*     */   public a getOnPageChangedListener()
/*     */   {
/* 380 */     return this.m;
/*     */   }
/*     */ 
/*     */   public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
/*     */   {
/* 385 */     boolean bool = super.onInterceptTouchEvent(paramMotionEvent);
/*     */ 
/* 387 */     if (paramMotionEvent.getAction() == 0) {
/* 388 */       this.f = ((int)paramMotionEvent.getX());
/* 389 */       this.g = ((int)paramMotionEvent.getY());
/* 390 */       if (!this.j) {
/* 391 */         this.h = false;
/* 392 */         this.i = false;
/*     */       }
/* 394 */     } else if (paramMotionEvent.getAction() == 2) {
/* 395 */       a(paramMotionEvent);
/*     */     }
/*     */ 
/* 398 */     if (this.i) {
/* 399 */       return false;
/*     */     }
/* 401 */     if (this.h) {
/* 402 */       this.j = true;
/* 403 */       return true;
/*     */     }
/*     */ 
/* 406 */     return bool;
/*     */   }
/*     */ 
/*     */   private void a(MotionEvent paramMotionEvent) {
/* 410 */     if ((!this.h) && (!this.i))
/*     */     {
/* 412 */       float f1 = Math.abs(this.f - paramMotionEvent.getX());
/* 413 */       float f2 = Math.abs(this.g - paramMotionEvent.getY());
/*     */ 
/* 415 */       if (f2 > f1 + 5.0F)
/* 416 */         this.i = true;
/* 417 */       else if (f1 > f2 + 5.0F)
/* 418 */         this.h = true; 
/*     */     }
/*     */   }
/*     */   public static abstract interface a { public abstract void a(int paramInt1, int paramInt2); }
/*     */ 
/*     */ 
/* 424 */   private class b implements View.OnTouchListener { private boolean b = false;
/*     */     private int c;
/*     */     private int d;
/* 427 */     private boolean e = true;
/*     */ 
/*     */     private b() {  } 
/* 430 */     public boolean onTouch(View paramView, MotionEvent paramMotionEvent) { if (((SwipeView.a(SwipeView.this) != null) && (!SwipeView.b(SwipeView.this))) || ((SwipeView.a(SwipeView.this) != null) && 
/* 431 */         (this.b)))
/*     */       {
/* 433 */         if (SwipeView.a(SwipeView.this).onTouch(paramView, paramMotionEvent)) {
/* 434 */           if (paramMotionEvent.getAction() == 1)
/*     */           {
/* 437 */             c(paramMotionEvent);
/*     */           }
/* 439 */           return true;
/*     */         }
/*     */       }
/*     */ 
/* 443 */       if (this.b)
/*     */       {
/* 445 */         this.b = false;
/* 446 */         return false;
/*     */       }
/*     */ 
/* 449 */       switch (paramMotionEvent.getAction()) {
/*     */       case 0:
/* 451 */         return a(paramMotionEvent);
/*     */       case 2:
/* 454 */         return b(paramMotionEvent);
/*     */       case 1:
/* 457 */         return c(paramMotionEvent);
/*     */       }
/* 459 */       return false; }
/*     */ 
/*     */     private boolean a(MotionEvent paramMotionEvent)
/*     */     {
/* 463 */       SwipeView.a(SwipeView.this, (int)paramMotionEvent.getX());
/* 464 */       SwipeView.b(SwipeView.this, (int)paramMotionEvent.getY());
/* 465 */       this.e = false;
/* 466 */       return false;
/*     */     }
/*     */ 
/*     */     private boolean b(MotionEvent paramMotionEvent) {
/* 470 */       int i = SwipeView.c(SwipeView.this) - (int)paramMotionEvent.getX();
/*     */       int j;
/* 473 */       if (i < 0)
/*     */       {
/* 475 */         j = this.c + 4 <= i ? 1 : -1;
/*     */       }
/*     */       else {
/* 478 */         j = this.c - 4 <= i ? 1 : -1;
/*     */       }
/*     */ 
/* 481 */       if ((j != this.d) && (!this.e))
/*     */       {
/* 483 */         SwipeView.a(SwipeView.this, (int)paramMotionEvent.getX());
/* 484 */         this.c = (SwipeView.c(SwipeView.this) - (int)paramMotionEvent.getX());
/*     */       } else {
/* 486 */         this.c = i;
/*     */       }
/*     */ 
/* 489 */       this.d = j;
/*     */ 
/* 491 */       if (SwipeView.b(SwipeView.this))
/*     */       {
/* 493 */         this.b = true;
/* 494 */         SwipeView.this.dispatchTouchEvent(MotionEvent.obtain(paramMotionEvent.getDownTime(), paramMotionEvent.getEventTime(), 
/* 495 */           0, SwipeView.c(SwipeView.this), SwipeView.d(SwipeView.this), paramMotionEvent.getPressure(), 
/* 496 */           paramMotionEvent.getSize(), paramMotionEvent.getMetaState(), paramMotionEvent.getXPrecision(), 
/* 497 */           paramMotionEvent.getYPrecision(), paramMotionEvent.getDeviceId(), paramMotionEvent.getEdgeFlags()));
/* 498 */         SwipeView.a(SwipeView.this, false);
/*     */ 
/* 500 */         return true;
/*     */       }
/* 502 */       return false;
/*     */     }
/*     */ 
/*     */     private boolean c(MotionEvent paramMotionEvent) {
/* 506 */       float f1 = SwipeView.this.getScrollX();
/* 507 */       float f2 = SwipeView.e(SwipeView.this).getMeasuredWidth() / SwipeView.f(SwipeView.this);
/* 508 */       float f3 = f1 / SwipeView.f(SwipeView.this);
/* 509 */       float f4 = 0.0F;
/*     */ 
/* 511 */       if (this.d == 1)
/*     */       {
/* 513 */         if (this.c > SwipeView.a())
/*     */         {
/* 515 */           if (SwipeView.g(SwipeView.this) < f2 - 1.0F)
/*     */           {
/* 517 */             f4 = (int)(f3 + 1.0F) * SwipeView.f(SwipeView.this);
/*     */           }
/* 519 */           else f4 = SwipeView.g(SwipeView.this) * SwipeView.f(SwipeView.this);
/*     */ 
/*     */         }
/* 523 */         else if (Math.round(f3) == f2 - 1.0F)
/*     */         {
/* 528 */           f4 = (int)(f3 + 1.0F) * SwipeView.f(SwipeView.this);
/*     */         }
/*     */         else {
/* 531 */           f4 = SwipeView.g(SwipeView.this) * SwipeView.f(SwipeView.this);
/*     */         }
/*     */ 
/*     */       }
/* 537 */       else if (this.c < -SwipeView.a())
/*     */       {
/* 539 */         f4 = (int)f3 * SwipeView.f(SwipeView.this);
/*     */       }
/* 542 */       else if (Math.round(f3) == 0)
/*     */       {
/* 547 */         f4 = (int)f3 * SwipeView.f(SwipeView.this);
/*     */       }
/*     */       else {
/* 550 */         f4 = SwipeView.g(SwipeView.this) * SwipeView.f(SwipeView.this);
/*     */       }
/*     */ 
/* 556 */       SwipeView.this.smoothScrollToPage((int)f4 / SwipeView.f(SwipeView.this));
/* 557 */       this.e = true;
/* 558 */       this.c = 0;
/* 559 */       SwipeView.b(SwipeView.this, false);
/* 560 */       SwipeView.c(SwipeView.this, false);
/*     */ 
/* 562 */       return true;
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.newxp.view.widget.SwipeView
 * JD-Core Version:    0.6.2
 */